package com.ptt.jituangou.widgets.listener

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

/**
 * Description: RecyclerView的滚动监听，用来判断RecyclerView滑动了多少Item的距离
 * 结合{@link com.ptt.jituangou.bean.event.FabEvent}，实现RecyclerView回到顶部功能
 * Data：2020/6/11-13:35
 * Author: TangJian
 */
class RvOnScrollListener : RecyclerView.OnScrollListener() {

    override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
        super.onScrollStateChanged(recyclerView, newState)
    }

    override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
        super.onScrolled(recyclerView, dx, dy)
        val layoutManager = recyclerView.layoutManager
        if (layoutManager is LinearLayoutManager) {
            val lastPosition = layoutManager.findLastVisibleItemPosition()
        }
    }
}